import configData from '../../../datas/queryMapConfig.json';
import { reactive } from "@vue/composition-api";
/**
 * 数据工具类
 */
const DataUtils = {
    /**
     * queryMapConfig.json 数据
     */
    data: null,
    /**
     * 返回查询对象
     */
    result: {
        view: null,
        idList: null,
        returnGeometry: null,
        returnFieldName: null,
        layerOption: null,
        tolerance: null,
        subLayerIds: null,
        where: null,
        outFields: null
    },


    


    /**
     * 获取json数据
     * @param {*} type 类型，如：querymapconfig.json 文件中key值
     */
    getConfigData(key = null) {
        if (!this.data) return;
        if (this.data.hasOwnProperty(key)) {
            let items = this.data[key];
            if ((items instanceof Array) && items && items.length > 0) {
                this.initResult();
                let owner = this;
                items.forEach(item => {
                    owner.result.idList.push(item.serviceName);
                    let returnGeometry = { parentId: item.serviceName, value: item.returnGeometry };
                    let returnFieldName = { parentId: item.serviceName, value: item.returnFieldName };
                    let layerOption = { parentId: item.serviceName, value: item.layerOption };
                    let tolerance = { parentId: item.serviceName, value: item.tolerance };
                    let subLayerIds = { parentId: item.serviceName, value: item.subLayerIds };
                    let where = { parentId: item.serviceName, value: item.where };
                    let outFields = { parentId: item.serviceName, value: item.outFields };
                    owner.result.returnGeometry.push(returnGeometry);
                    owner.result.returnFieldName.push(returnFieldName);
                    owner.result.layerOption.push(layerOption);
                    owner.result.tolerance.push(tolerance);
                    owner.result.subLayerIds.push(subLayerIds);
                    owner.result.where.push(where);
                    owner.result.outFields.push(outFields);
                });
            }
        }
        return this.result;
    },

    /**
     * 初始话结果对象
     */
    initResult() {
        return this.result = {
            view: [],
            idList: [],
            returnGeometry: [],
            returnFieldName: [],
            layerOption: [],
            tolerance: [],
            subLayerIds: [],
            where: [],
            outFields: []
        }
    },
    /**
     * 初始化Json数据
     */
    initJsonData() {
        let config = reactive({
            configData
        });
        this.data = config["configData"];
    }

}
export default DataUtils;